package com.mva.Expense_DAO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.mva.database.DB_Pipe;

public class ExpenseDB implements ExpenseDAO
  {
   private Connection con = null;
	   
   public ExpenseDB()
	 {
	 }

   /*******************************************************************************
	Expense reader methods
   *******************************************************************************/
   
   public boolean existsExpense (int stckNo, int seq)
     {
	  try
		{
	     String exists = "SELECT Seq "         +
				           "FROM expense "     +
				          "WHERE Stck_No = ? " +
				            "AND Seq     = ?";
         con                   = DB_Pipe.DB_Connect();
	     PreparedStatement ps  = con.prepareStatement(exists);
		 ps.setInt(1, stckNo);
		 ps.setInt(2, seq);
		 ResultSet         rs  = ps.executeQuery();
		 if (rs.next())
		   {
		    rs.close();
		    ps.close();
			DB_Pipe.DB_Disconnect(con);
		    return true;
		   }
		 else
		   {
		    rs.close();
		    ps.close();
			DB_Pipe.DB_Disconnect(con);
		    return false;
		   }
		}
	  catch(SQLException sqle)
		{
		 //sqle.printStackTrace();	// for debugging
		 return false;
		}
     }
   
   public Expense getExpense (int stckNo, int seq)
     {
      Expense e = new Expense();
      return e;   
     }
   
   public boolean getExpenses (ArrayList<Expense> expns, int stckNo)
     {
	  return true;
     }
   
   /*******************************************************************************
	Expense writer methods
   *******************************************************************************/
   
   public boolean addExpense (Expense expns)
     {
	  return true;
     }
   
   public boolean updateExpense (Expense expns)
     {
	  return true;   
     }
   
   public boolean deleteExpense (Expense expns)
     {
	  return true;  
     }
  }
